<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <router-view></router-view>
    </div>
    <script src="./vue.min.js"></script>
    <script src="./router.js"></script>
    <script>
        const child = {
            template: `
                <div>这是页面一的子组件</div>
            `,
            beforeDestroy() {
                console.log('页面1的子组件销毁之前')
            },

            destroyed() {
                console.log('页面1的子组件销毁之后')
            }
        }
        const page1 = {
            components: {
                child
            },
            template: `
                <div>
                    这是页面一
                    <child></child>
                    <router-link to="/page2">进入页面2</router-link>
                </div>
            `,
            beforeDestroy() {
                console.log('页面1销毁之前')
            },

            destroyed() {
                console.log('页面1销毁之后')
            },
        }
        const page2 = {
            template: `
                <div>
                    这是页面二
                    <router-link to="/">进入页面1</router-link>
                </div>
            `,
            beforeCreate() {
                console.log('页面2创建之前')
            },

            created() {
                console.log('页面2创建之后')
            },

            beforeMount() {
                console.log('页面2渲染之前')
            },

            mounted() {
                console.log('页面2渲染之后')
            },

            beforeDestroy() {
                
            },

            destroyed() {
                
            },
        }
        let router = new VueRouter({
            routes: [
                {
                    path: '/',
                    component: page1
                },
                {
                    path: '/page2',
                    component: page2
                }
            ]
        })
        new Vue({
            el: '#app',
            router
        })
    </script>
</body>
</html>